<?php

require_once 'FModel.class.php';
require_once 'FForm.class.php';

class FDefaultModel extends FModel
{
        
    private $editForm;
    private $insertForm;
    private $searchForm;
    private $viewForm;
    
    public function getForm()
    {
        if ( !$this->getInsertForm() )
        {
            $insertForm = new FEditForm();
            $insertForm->setController($this->controller);
            $insertForm->setAction(FEditForm::FUNCTION_INSERT);
            $insertForm->createTableFields();
            $this->setInsertForm($insertForm);
        }
        
        if ( !$this->getEditForm() )
        {
            $editForm = new FEditForm();
            $editForm->setController($this->controller);
            $editForm->setAction(FEditForm::FUNCTION_UPDATE);
            $editForm->createTableFields();
            $this->setEditForm($editForm);
        }
        
        // TODO: view form?
        
        $searchForm = new FSearchForm();
        $searchForm->setController($this->controller);
        $searchForm->setTitle($this->title ? $this->title : $this->getName());
        $searchForm->setInsertForm($this->getInsertForm());
        $searchForm->setEditForm($this->getEditForm());
        $this->setSearchForm($searchForm);
        
        return $searchForm;
    }
    
    public function getEditForm() {
        return $this->editForm;
    }

    public function setEditForm($editForm) {
        $this->editForm = $editForm;
    }

    public function getInsertForm() {
        return $this->insertForm;
    }

    public function setInsertForm($insertForm) {
        $this->insertForm = $insertForm;
    }

    public function getSearchForm() {
        return $this->searchForm;
    }

    public function setSearchForm($searchForm) {
        $this->searchForm = $searchForm;
    }

    public function getViewForm() {
        return $this->viewForm;
    }

    public function setViewForm($viewForm) {
        $this->viewForm = $viewForm;
    }
    
}

?>
